package com.beiding.pojo.room;

import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class RoomFillInHelper {
    public void makeLocation(Room room) {
        if (room.getLocation() == null) {
            room.setLocation(new Location());
        }
    }

    //初始化价格表单.负数表示未被赋值
    public void initPrices(Room room,int num) {

        if (room.getPrices() == null) {
            List<Price> prices = new ArrayList<>();
            for (int i = 0; i < num; i++) {
                Price price = new Price();
                price.setPrice(-1);
                price.setTimeUnit(-1);
                price.setNum(-1);
                prices.add(price);
            }
            room.setPrices(prices);

        } else {
            int p = num - room.getPrices().size();

            //补足空缺的占位
            for (int i = 0; i < p; i++) {
                Price price = new Price();
                price.setPrice(-1);
                price.setTimeUnit(-1);
                price.setNum(-1);
                room.getPrices().add(price);
            }
        }

    }


}
